import { NestFactory } from "@nestjs/core";
import { AppModule } from "./app.module";
import { ResponseFormatInterceptor } from "@common/interceptors/response-format.interceptor";
import { HttpExceptionFilter } from "@common/filters/http-exception.filter";
import { NotFoundExceptionFilter } from "@common/filters/not-found.filter";
import { DocumentBuilder, SwaggerModule } from "@nestjs/swagger";

// import { ValidationPipe } from '@nestjs/common';
async function bootstrap() {
  const app = await NestFactory.create(AppModule);

  const config = new DocumentBuilder()
    .setTitle("接口文档")
    .setDescription("描述")
    .setVersion("1.0")
    .build();
  const document = SwaggerModule.createDocument(app, config);
  SwaggerModule.setup("docs", app, document);
  // app.useGlobalPipes(new ValidationPipe({ transform: true }));
  // 注册全局拦截器
  app.useGlobalInterceptors(new ResponseFormatInterceptor());

  // 注册全局异常过滤器
  app.useGlobalFilters(new HttpExceptionFilter());
  // 注册全局过滤器 - 404
  app.useGlobalFilters(new NotFoundExceptionFilter());

  await app.listen(1000);
}

bootstrap();
